home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Actual 85 Febrero 2004.iso / Experto / Apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F251768_apr_sdbm.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-31  |  7.9 KB  |  214 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. /*
  56.  * sdbm - ndbm work-alike hashed database library
  57.  * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
  58.  * author: oz@nexus.yorku.ca
  59.  * status: ex-public domain
  60.  */
  61.  
  62. #ifndef APR_SDBM_H
  63. #define APR_SDBM_H
  64.  
  65. #include "apu.h"
  66. #include "apr_errno.h"
  67. #include "apr_file_io.h"   /* for apr_fileperms_t */
  68.  
  69. /** 
  70.  * @file apr_sdbm.h
  71.  * @brief apr-util SDBM library
  72.  */
  73. /**
  74.  * @defgroup APR_Util_DBM_SDBM SDBM library
  75.  * @ingroup APR_Util_DBM
  76.  * @{
  77.  */
  78.  
  79. /**
  80.  * Structure for referencing an sdbm
  81.  */
  82. typedef struct apr_sdbm_t apr_sdbm_t;
  83.  
  84. /**
  85.  * Structure for referencing the datum record within an sdbm
  86.  */
  87. typedef struct {
  88.     /** pointer to the data stored/retrieved */
  89.     char *dptr;
  90.     /** size of data */
  91.     int dsize;
  92. } apr_sdbm_datum_t;
  93.  
  94. /* The extensions used for the database files */
  95. /** SDBM Directory file extension */
  96. #define APR_SDBM_DIRFEXT    ".dir"
  97. /** SDBM page file extension */
  98. #define APR_SDBM_PAGFEXT    ".pag"
  99.  
  100. /* flags to sdbm_store */
  101. #define APR_SDBM_INSERT     0   /**< Insert */
  102. #define APR_SDBM_REPLACE    1   /**< Replace */
  103. #define APR_SDBM_INSERTDUP  2   /**< Insert with duplicates */
  104.  
  105. /**
  106.  * Open an sdbm database by file name
  107.  * @param db The newly opened database
  108.  * @param name The sdbm file to open
  109.  * @param mode The flag values (APR_READ and APR_BINARY flags are implicit)
  110.  * <PRE>
  111.  *           APR_WRITE          open for read-write access
  112.  *           APR_CREATE         create the sdbm if it does not exist
  113.  *           APR_TRUNCATE       empty the contents of the sdbm
  114.  *           APR_EXCL           fail for APR_CREATE if the file exists
  115.  *           APR_DELONCLOSE     delete the sdbm when closed
  116.  *           APR_SHARELOCK      support locking across process/machines
  117.  * </PRE>
  118.  * @param perms Permissions to apply to if created
  119.  * @param p The pool to use when creating the sdbm
  120.  * @remark The sdbm name is not a true file name, as sdbm appends suffixes 
  121.  * for seperate data and index files.
  122.  */
  123. APU_DECLARE(apr_status_t) apr_sdbm_open(apr_sdbm_t **db, const char *name, 
  124.                                         apr_int32_t mode, 
  125.                                         apr_fileperms_t perms, apr_pool_t *p);
  126.  
  127. /**
  128.  * Close an sdbm file previously opened by apr_sdbm_open
  129.  * @param db The database to close
  130.  */
  131. APU_DECLARE(apr_status_t) apr_sdbm_close(apr_sdbm_t *db);
  132.  
  133. /**
  134.  * Lock an sdbm database for concurency of multiple operations
  135.  * @param db The database to lock
  136.  * @param type The lock type
  137.  * <PRE>
  138.  *           APR_FLOCK_SHARED
  139.  *           APR_FLOCK_EXCLUSIVE
  140.  * </PRE>
  141.  * @remark Calls to apr_sdbm_lock may be nested.  All apr_sdbm functions
  142.  * perform implicit locking.  Since an APR_FLOCK_SHARED lock cannot be 
  143.  * portably promoted to an APR_FLOCK_EXCLUSIVE lock, apr_sdbm_store and 
  144.  * apr_sdbm_delete calls will fail if an APR_FLOCK_SHARED lock is held.
  145.  * The apr_sdbm_lock call requires the database to be opened with the
  146.  * APR_SHARELOCK mode value.
  147.  */
  148. APU_DECLARE(apr_status_t) apr_sdbm_lock(apr_sdbm_t *db, int type);
  149.  
  150. /**
  151.  * Release an sdbm lock previously aquired by apr_sdbm_lock
  152.  * @param db The database to unlock
  153.  */
  154. APU_DECLARE(apr_status_t) apr_sdbm_unlock(apr_sdbm_t *db);
  155.  
  156. /**
  157.  * Fetch an sdbm record value by key
  158.  * @param db The database 
  159.  * @param value The value datum retrieved for this record
  160.  * @param key The key datum to find this record
  161.  */
  162. APU_DECLARE(apr_status_t) apr_sdbm_fetch(apr_sdbm_t *db, 
  163.                                          apr_sdbm_datum_t *value, 
  164.                                          apr_sdbm_datum_t key);
  165.  
  166. /**
  167.  * Store an sdbm record value by key
  168.  * @param db The database 
  169.  * @param key The key datum to store this record by
  170.  * @param value The value datum to store in this record
  171.  * @param opt The method used to store the record
  172.  * <PRE>
  173.  *           APR_SDBM_INSERT     return an error if the record exists
  174.  *           APR_SDBM_REPLACE    overwrite any existing record for key
  175.  * </PRE>
  176.  */
  177. APU_DECLARE(apr_status_t) apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key,
  178.                                          apr_sdbm_datum_t value, int opt);
  179.  
  180. /**
  181.  * Delete an sdbm record value by key
  182.  * @param db The database 
  183.  * @param key The key datum of the record to delete
  184.  * @remark It is not an error to delete a non-existent record.
  185.  */
  186. APU_DECLARE(apr_status_t) apr_sdbm_delete(apr_sdbm_t *db, 
  187.                                           const apr_sdbm_datum_t key);
  188.  
  189. /**
  190.  * Retrieve the first record key from a dbm
  191.  * @param db The database 
  192.  * @param key The key datum of the first record
  193.  * @remark The keys returned are not ordered.  To traverse the list of keys
  194.  * for an sdbm opened with APR_SHARELOCK, the caller must use apr_sdbm_lock
  195.  * prior to retrieving the first record, and hold the lock until after the
  196.  * last call to apr_sdbm_nextkey.
  197.  */
  198. APU_DECLARE(apr_status_t) apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
  199.  
  200. /**
  201.  * Retrieve the next record key from an sdbm
  202.  * @param db The database 
  203.  * @param key The key datum of the next record
  204.  */
  205. APU_DECLARE(apr_status_t) apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key);
  206.  
  207. /**
  208.  * Returns true if the sdbm database opened for read-only access
  209.  * @param db The database to test
  210.  */
  211. APU_DECLARE(int) apr_sdbm_rdonly(apr_sdbm_t *db);
  212. /** @} */
  213. #endif /* APR_SDBM_H */
  214.